//
//  TTHongBaoView.m
//  TaoTuo
//
//  Created by admin on 2019/12/6.
//  Copyright © 2019 admin. All rights reserved.
//

#import "TTHongBaoView.h"
#import <UIView+TYAlertView.h>
#import <UIImageView+WebCache.h>

#import "TTCouponsPopView.h"

@interface TTHongBaoView ()

@property (weak, nonatomic) IBOutlet UIImageView *headerImageView;
@property (weak, nonatomic) IBOutlet UILabel *kefuNameLabel;
@property (weak, nonatomic) IBOutlet UIButton *receiveBtn;

@property (nonatomic, copy) NSString *urlString;

@end

@implementation TTHongBaoView

- (void)awakeFromNib
{
    [super awakeFromNib];
    
    self.receiveBtn.layer.cornerRadius = 20;
    self.headerImageView.layer.cornerRadius = 30;
    self.headerImageView.layer.masksToBounds = YES;
    
}

- (void)setHeaderImageWithUrl:(NSString *)urlString kefuName:(NSString *)name
{
    self.urlString = urlString;
    [self.headerImageView sd_setImageWithURL:[NSURL URLWithString:urlString] placeholderImage:[UIImage imageNamed:@"header_img"] options:SDWebImageRetryFailed];
    self.kefuNameLabel.text = name;
}

///关闭页面
- (IBAction)closeButtonClick:(id)sender {
    
    [self hideInWindow];
    
}

///领取红包
- (IBAction)receiveBtnClick:(id)sender {
    
    
    [self hideInWindow];
    
    [self exchangeCoupons];
    
}


///兑换优惠券
- (void)exchangeCoupons
{
    NSDictionary *dic = @{
        @"param.couponCode" : @"NewUserEnjoyment",
        @"param.source" : @"淘托APP",
    };
    @weakify(self)
    [[LLNetworkManagerTool sharedManager] postUrlString:exchangeCoupon_api parameters:dic success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        @strongify(self)
        NSString *money = [NSString stringWithFormat:@"%@", responseObject[@"CouponPrice"]];
        TTCouponsPopView *view = [TTCouponsPopView createViewFromNib];
        [view setHeaderImageWithUrl:self.urlString money:money];
        [view showInWindowWithBackgoundTapDismissEnable:YES];
        
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nullable error) {
        
    } showLoadingInView:self.viewController.view];
    
}



@end
